var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    text: '分销消费积分',
    active: 0,

    current_page:1,
    last_page:1,
    list:[],


    expect_commission: 0,
    unsettle_commission: 0,
    settle_commission: 0,
    close_commission: 0,
    invalid_commission: 0,
    nickname: '',
    avatar_image: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
    this.getList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  onChange(e){
    this.setData({active:e.detail.name})
    this.getList()
  },
  getMoreData(){
    let page = this.data.current_page + 1;
    app._getNetWork({
      url:app.getNetAddresss("plugin.commission-point.frontend.index.list"),
      data:{page,status:this.data.active},
      success:(res)=>{
        if(res.data.result){
          let arr = this.data.list.concat(res.data.data.data),
          last_page = res.data.data.last_page,
          current_page=res.data.data.current_page;
          this.setData({
            list:arr,
            last_page,
            current_page
          })
        }
      }
    })
  },
  getList(){
    app._postNetWork({
      url:app.getNetAddresss("plugin.commission-point.frontend.index.list"),
      data:{
        status:this.data.active,
      },
      success:(res)=>{
        if(res.data.result){
          this.setData({
            list:res.data.data.data,
            last_page:res.data.data.last_page
          })
        }
      }
    })
  },
  getData() {
    app._getNetWork({
      url:app.getNetAddresss("plugin.commission-point.frontend.index.index"),
      success:(res)=>{
        if(res.data.result){
        let { expect_commission, unsettle_commission, settle_commission, close_commission, invalid_commission, member: { nickname, avatar_image } } = res.data.data;
        wx.setNavigationBarTitle({
          title: res.data.data.plugin_name || '分销消费积分',
        })
          this.setData({
            expect_commission,
            unsettle_commission,
            settle_commission,
            close_commission,
            invalid_commission,
            nickname,
            avatar_image
          })
        }
      }
    })
  },
  

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.current_page>=this.data.last_page){
      return false;
    }
    this.getMoreData()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})